defineClass('switch', Virtual, function (base) {


    // 检测目标
    defineProperty(this, 'test', {
        
        defaultValue: true,
        convert: null,
        onchange: invalidateVirtualObject
    });


    this.getVisualObjects = function (outputs, destroyObjectFn) {

        var test = this.test;
        var last = outputs.length;
        var children = this.__children;
        var index = 0;
        var item, any;

        while (item = children[index++])
        {
            if ((any = item.__switch) && (any === 2 || item.when === test))
            {
                // 未加载模板则先加载
                if (!item.__children[0] && (any = item.__template))
                {
                    buildObjectChildren(item, any);
                }

                item.getVisualObjects(outputs, destroyObjectFn);
                break;
            }
        }

        // 上次渲染的子项集合
        children = this.__last;

        // 新添加的子项数量
        index = 0;

        // 处理新添加的子项
        while (item = outputs[last++])
        {
            // 更新新添加的子项
            children[index++] = item;

            // 设置新的组件状态为显示
            if (any = item.dom)
            {
                any = any.style;

                if (any.display === 'none')
                {
                    any.display = item.__display || '';
                }
                else
                {
                    item.__display = any.display;
                }
            }
        }

        // 保证每一次渲染的子项数不小于上一次渲染的子项数以提升渲染性能
        // 添加原来渲染过的多余的子项并隐藏
        while (item = children[index++])
        {
            outputs.push(item);

            if (any = item.dom)
            {
                any.style.display = 'none';
            }
        }
    }


    this.destroy = function () {

        this.__last = null;
        base.destroy.call(this);
    }


}, function Switch() {

    this.__last = [];
    this.init();
});



defineClass('case', Virtual, function (base) {


    // switch类型标记
    this.__switch = 1;


    // 测试条件是否成立
    defineProperty(this, 'when', {

        defaultValue: null,
        onchange: invalidateVirtualObject
    });



    this.__load = loadVirtuallDelay;


}, function SwitchCase() {

    this.init();
});



defineClass('default', Virtual, function (base) {


    // switch类型标记
    this.__switch = 2;


    this.__load = loadVirtuallDelay;


}, function SwitchDefault() {

    this.init();
});
